package com.scud.order.controller;

import com.scud.common.result.Result;
import com.scud.model.order.dto.CreateOrderDto;
import com.scud.model.order.pojo.Order;
import com.scud.model.order.vo.OrderInfoVo;
import com.scud.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author vermouth
 */
@RestController
@RequestMapping("/api/order/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param createOrderDto
     * @return
     */
    @PostMapping("/createOrder")
    public Result<String> createOrder(@RequestBody CreateOrderDto createOrderDto){
        String orderId = orderService.createOrder(createOrderDto);
        return Result.success(orderId);
    }

    /**
     * 根据订单id获取订单信息
     * @param orderId:
     * @return Result
     * @author vermouth
     */
    @GetMapping("/getOrderInfo/{orderId}")
    public Result getOrderInfo(@PathVariable Long orderId){
        log.info("根据订单id获取订单信息：{}",orderId);
        OrderInfoVo vo=orderService.getOrderIndo(orderId);
        return Result.success(vo);
    }

    /**
     * 获取当前用户的订单列表
     * @param :
     * @return Result
     * @author vermouth
     */
    @GetMapping("getCurrentOrderList")
    public Result getCurrentOrderList(){
        log.info("获取当前用户的订单列表");
        List<Order> orderList=orderService.getCurrentOrderList();
        return Result.success(orderList);
    }

    /**
     * 模拟支付功能
     * @param orderId:
     * @return Result
     * @author vermouth
     */
    @PostMapping("/payOrder/{orderId}")
    public Result payOrder(@PathVariable Long orderId){
        log.info("模拟支付功能：{}",orderId);
        orderService.payOrder(orderId);
        return Result.success();
    }
}
